package mcommand;

import java.applet.Applet;
import java.applet.AudioClip;
import java.net.URL;

/**
 * Handles how to play one, play in a loop and stop a soundfile for effects.
 *
 * @author Marcel, Christian, Klaus
 */
public class SoundHandler {
    // Sound player
    private AudioClip song;
    // Sound Path
    private URL songPath;

    /**
     * Defines a new sound applet with that set filename.
     *
     * @param filename
     *            path to the file
     */
    public SoundHandler(final String filename) {
        // defines a variable where to find the data
        songPath = getClass().getResource(filename);
        // loads the sound
        song = Applet.newAudioClip(songPath);
    }

    /**
     * Plays the Sound in a loop.
     */
    public final void playSound() {
        song.loop();
    }

    /**
     * Stops the sound.
     */
    public final void stopSound() {
        song.stop();
    }

    /**
     * Plays the sound one time.
     */
    public final void playSoundOnce() {
        song.play();
    }
}
